package models

type consumer struct {
	Consumer_id int64 `gorm:"colunmn:consumer_id"`
	Consumer_name string `gorm:"colunmn:consumer_name"`
	Consumer_address string `gorm:"colunmn:consumer_address"`
	Consumer_postcode string `gorm:"colunmn:consumer_postcode"`
	Consumer_phone string `gorm:"colunmn:consumer_phone"`
}

func GetAllconsumer() (error, []consumer, int64)  {
	var consumerdata []consumer
	//page := goodsParam["page"].(int)
	//pageSize := goodsParam["limit"].(int)
	//searchText := goodsParam["searchText"].(string)
	var total int64
	err := db.Table("consumer").Order("consumer_id ASC").Count(&total).Find(&consumerdata).Error

	return err, consumerdata, total
}

func Addconsumer() (error, consumer) {

	//a.BindJSON(&injurydata)
	//injurydata.Is_del = false
	//injurydata.Update_username = "系统管理员"
	//injurydata.Update_time = time.Now()
	consumerdata := consumer{6,"葛鸣宇","扎兰屯","162650","15647090169"}
	err := db.Table("consumer").Create(&consumerdata).Error
	return err, consumerdata
}

func Updateconsumer() (error, consumer) {

	//a.BindJSON(&injurydata)
	//injurydata.Update_username = "系统管理员"
	//injurydata.Update_time = time.Now()
	consumerdata := consumer{6,"刘泽民","四川成都","1234","147283193633"}
	err := db.Table("consumer").Where("consumer_id = ?", consumerdata.Consumer_id).Updates(&consumerdata).Error
	return err, consumerdata
}

func Delconsumer() error {
	id := 6
	err := db.Table("consumer").Where("consumer_id = ?", id).Delete(consumer{}).Error
	return err
}